package com.hundsun.finance.controller;

import com.hundsun.finance.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/test")
public class UrlRestFulController {

    private Map<String,User> caches=new HashMap<String, User>();

    @RequestMapping("/addUser.do")
    @ResponseBody
    public User addUser(String id, String name){
        User user=new User();
        user.setId(id);
        user.setName(name);
        caches.put(id,user);
        return user;
    }

    @RequestMapping("/updateUser.do")
    @ResponseBody
    public User updateUser(String id, String name){
        User user=caches.get(id);
        user.setName(name);
        return user;
    }

    @RequestMapping("/deleteUser.do")
    @ResponseBody
    public Map<String,User> deleteUser(String id){
        caches.remove(id);
        return  caches;
    }

    @RequestMapping("/queryUserById.do")
    @ResponseBody
    public User addUser(String id){
        return caches.get(id);
    }


}
